package com.gzyj.jtt808.v2019.protocol.jtt1078;

import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2019.Package;
import com.gzyj.jtt808.v2019.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.nio.charset.Charset;
@Data
public class JTT808_0x9101 extends Package implements Serializable {
    @ApiModelProperty("视频服务器IP地址")
    private String ServerIp;

    @ApiModelProperty("视频服务器TCP端口号")
    private Integer TcpPort;
    @ApiModelProperty("视频服务器UDP端口号")
    private Integer UdpPort;

    @ApiModelProperty("逻辑通道号")
    private Byte ChannelNo;

    @ApiModelProperty("数据类型")
    private Byte DataType;

    @ApiModelProperty("码流类型")
    private Byte StreamType;

    public JTT808_0x9101() {
        super(BusinessDataType.实时音视频传输请求.getCode());
    }

    @Override
    public void encodeImpl(ByteBuf buf) {
        buf.writeByte(this.ServerIp.getBytes(Charset.forName("GBK")).length);
        buf.writeCharSequence(this.ServerIp,Charset.forName("GBK"));
        buf.writeShort(this.TcpPort);
        buf.writeShort(this.UdpPort);
        buf.writeByte(this.ChannelNo);
        buf.writeByte(this.DataType);
        buf.writeByte(this.StreamType);
    }

    @Override
    public JTT808_0x9101 decodeImpl(ByteBuf buf) {
        int len= Byte.toUnsignedInt(buf.readByte());
        this.ServerIp= HexBytesUtil.parseString(HexBytesUtil.readByOffset(buf,len));
        this.TcpPort=buf.readUnsignedShort();
        this.UdpPort=buf.readUnsignedShort();
        this.ChannelNo=buf.readByte();
        this.DataType=buf.readByte();
        this.StreamType=buf.readByte();


        return this;
    }
}
